package com.tinyseed.emcp.api.basicdata.service.impl;

import com.tinyseed.emcp.api.basicdata.domain.Workshop;
import com.tinyseed.emcp.api.basicdata.model.WorkshopOutputDTO;
import com.tinyseed.emcp.api.basicdata.repository.WorkshopRepository;
import com.tinyseed.emcp.api.basicdata.service.WorkshopService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WorkshopServiceImpl implements WorkshopService {

    private final WorkshopRepository workshopRepository;

    public WorkshopServiceImpl(WorkshopRepository workshopRepository) {
        this.workshopRepository = workshopRepository;
    }

    @Override
    public List<WorkshopOutputDTO> getListByEnterpriseId(Long id) {
        List<Workshop> list = workshopRepository.findAllByEnterpriseId(id);
        List<WorkshopOutputDTO> workshopOutputDTOList = new ArrayList<>();
        list.forEach(workshop -> {
            WorkshopOutputDTO workshopOutputDTO = new WorkshopOutputDTO();
            BeanUtils.copyProperties(workshop, workshopOutputDTO);
            workshopOutputDTOList.add(workshopOutputDTO);
        });
        return workshopOutputDTOList;
    }
}
